Skip to content

Conversation

@shitikanth
Copy link

@shitikanth shitikanth commented Jan 9, 2026

Attempts to fix #2816

The maven plugin recalculates the list of dirty files using GitRatchetMaven::getDirtyFiles for each maven module and FormatterFactory. Calculating the list is expensive for large git repositories.

This PR introduces a cache that stores the set of dirty files for a given (repository, ratchetFrom) combination and returns the cached value when available.

On a large git repository with >20 modules and >10k java files, this change reduces the time to run spotless:check from ~7s to <1s.

@shitikanth
Copy link
Author

Impact on larger codebases is even more dramatic. For example, I tried testing the performance of spotless:check on real-world projects like apache/flink and aws-java-sdk-v2 by running mvn spotless:check -Dspotless.ratchetFrom=origin/master -Pspotless with the following profile added -

		<profile>
			<id>spotless</id>
			<build>
				<plugins>
					<plugin>
						<groupId>com.diffplug.spotless</groupId>
						<artifactId>spotless-maven-plugin</artifactId>
						<version>3.0.0</version>
						<configuration>
							<ratchetFrom>${spotless.ratchetFrom}</ratchetFrom>
							<java>
								<indent>
									<tabs>true</tabs>
									<spacesPerTab>4</spacesPerTab>
								</indent>
							</java>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
project runtime (before) runtime (after)
aws/aws-sdk-java-v2 09:46 min 2.80 s
apache/flink 01:39 min 2.86 s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spotless maven plugin is slow on large project with several maven submodules

1 participant